**************************************************
* This program performs the main empirical tests *
* on productivity of staying inventors           *
* reported in Table 3 Panel C & robustness tests *
**************************************************

	clear all
	global path "C:\cow"
	global out "$path\out"
	use "$path\inventor_stayer.dta"
	set more off

	*Convert strings to numerics
	encode state, gen(lstateFE)
	encode incorp, gen(istateFE)
	encode patgroup, gen(patgroupFE)
	encode class, gen(patclassFE)

	*Set timeframe 
	drop if pyear < 1996 
	drop if pyear > 2018 
		

	*Drop if missing headquarter state
	drop if missing(state)
	*Drop if missing state of incorporation
	drop if missing(incorp)
	*Drop if not incorporated in U.S. state
	drop if inlist(incorp, "AS", "INTL", "PR", "TT", "VI")

	
	drop if missing(permno)

	keep if leaving==0

	*Generate variables
	
	gen patcitespyear_countclassadjt=patcitespyear_countclassadj*1000
	gen patcites5pyear_countclassadjt=patcites5pyear_countclassadj*1000
	
	local pat "patcountpyear patcountpyear_adj patcountpyear_fclassadj patcitespyear patcitespyear_countclassadj patcitespyear_countclassadjt patcitespyear_fyearadj  patcitespyear_fclassadj  patcitespyear_fyearadjt  patcitespyear_fclassadjt  generality originality originality_alt patcites5pyear patcites5pyear_countclassadj patcites5pyear_countclassadjt patcites5pyear_fyearadj  patcites5pyear_fclassadj  patcites5pyear_fyearadjt  patcites5pyear_fclassadjt  generality5 originality5  " 
	foreach v of local pat {
		replace `v'=0 if missing(`v')
		gen ln_`v' = log(1+`v')
	}
	

	local statelist "DE OK MO KS TX NV NJ MD WA"
	gen treatment = 0
	foreach state of local statelist {
			replace treatment = 1 if incorp == "`state'"
	}

	*Create macros for year in which law was passed
	local DE_cow = 2001
	local OK_cow = 2002
	local MO_cow = 2004
	local KS_cow = 2005
	local TX_cow = 2006
	local NV_cow = 2008
	local NJ_cow = 2011
	local MD_cow = 2015
	local WA_cow = 2016

	*Initiate statelist macro
	local statelist "DE OK MO KS TX NV NJ MD WA"

	*cow: indicator equal to one if firm is incorporated in a state that has passed a corporate opportunities law
	gen cow = 0
	foreach state of local statelist {
			replace cow = 1 if incorp == "`state'" & pyear >= ``state'_cow'
	}




	*Create macros for year in which law was passed
	local DE_cow = 2001
	local OK_cow = 2002
	local MO_cow = 2004
	local KS_cow = 2005
	local TX_cow = 2006
	local NV_cow = 2008
	local NJ_cow = 2011
	local MD_cow = 2015
	local WA_cow = 2016

	*Initiate statelist macro
	local statelist "DE OK MO KS TX NV NJ MD WA"

	*cow: indicator equal to one if firm location in a state that has passed a corporate opportunities law
	gen icow = 0
	foreach state of local statelist {
			replace icow = 1 if state == "`state'" & pyear >= ``state'_cow'
	}
	
	
*******************************
* Table 3 Panel C Regressions *
*******************************

		reghdfe ln_patcountpyear_adj cow , absorb(inventor_id pyear#patgroupFE) vce(robust )
		reghdfe ln_patcitespyear_countclassadjt cow , absorb(inventor_id permno pyear#patclassFE) vce(robust)
		reghdfe generality cow , absorb(inventor_id permno pyear#patgroupFE) vce(robust)
		reghdfe originality cow , absorb(inventor_id permno pyear#patgroupFE) vce(robust)

		

		

		
		
		
		
		
*======================================*
*           ROBUSTNESS TESTS	       *
*======================================*
		
		* noncompete index		
		gen nceindex=0
		replace nceindex=5 if incorp=="AL"
		replace nceindex=3 if incorp=="AK"
		replace nceindex=3 if incorp=="AZ"
		replace nceindex=5 if incorp=="AR"
		replace nceindex=0 if incorp=="CA"
		replace nceindex=1 if incorp=="CO"
		replace nceindex=2 if incorp=="CO" & pyear>=1992 
		replace nceindex=3 if incorp=="CO" & pyear>=2012 
		replace nceindex=4 if incorp=="CT"
		replace nceindex=3 if incorp=="CT" & pyear>=1992
		replace nceindex=6 if incorp=="DE"
		replace nceindex=7 if incorp=="DC"
		replace nceindex=7 if incorp=="FL"
		replace nceindex=9 if incorp=="FL" & pyear>=1997
		replace nceindex=5 if incorp=="GA"
		replace nceindex=6 if incorp=="GA" & pyear>=2005
		replace nceindex=7 if incorp=="GA" & pyear>=2011
		replace nceindex=3 if incorp=="HI"
		replace nceindex=4 if incorp=="HI" & pyear>=2007
		replace nceindex=5 if incorp=="ID"
		replace nceindex=6 if incorp=="ID" & pyear>=1992
		replace nceindex=7 if incorp=="ID" & pyear>=2009
		replace nceindex=5 if incorp=="IL"
		replace nceindex=6 if incorp=="IL" & (2012<=pyear<=2013) 
		replace nceindex=5 if incorp=="IN"
		replace nceindex=6 if incorp=="IA"
		replace nceindex=6 if incorp=="KS"
		replace nceindex=7 if incorp=="KS" & pyear>=2008
		replace nceindex=6 if incorp=="KY"
		replace nceindex=5 if incorp=="KY" & pyear>=2015
		replace nceindex=2 if incorp=="LA" & pyear<=1991
		replace nceindex=4 if incorp=="LA" & (1992<=pyear<=2001)
		replace nceindex=4 if incorp=="LA" & (2004<=pyear)
		replace nceindex=4 if incorp=="ME"
		replace nceindex=5 if incorp=="MD"
		replace nceindex=6 if incorp=="MA"
		replace nceindex=5 if incorp=="MI"
		replace nceindex=5 if incorp=="MN"
		replace nceindex=4 if incorp=="MS"
		replace nceindex=5 if incorp=="MS" & pyear>=2009
		replace nceindex=7 if incorp=="MO"
		replace nceindex=2 if incorp=="MT"
		replace nceindex=4 if incorp=="NE"
		replace nceindex=5 if incorp=="NV"
		replace nceindex=2 if incorp=="NH"
		replace nceindex=1 if incorp=="NH" & pyear>=2013
		replace nceindex=4 if incorp=="NJ"
		replace nceindex=2 if incorp=="NM"
		replace nceindex=3 if incorp=="NY"
		replace nceindex=4 if incorp=="NC"
		replace nceindex=0 if incorp=="ND"
		replace nceindex=4 if incorp=="OH"
		replace nceindex=5 if incorp=="OH" & pyear>=1992
		replace nceindex=6 if incorp=="OH" & pyear>=2005
		replace nceindex=1 if incorp=="OK"
		replace nceindex=6 if incorp=="OR"
		replace nceindex=5 if incorp=="OR" & pyear>=2008
		replace nceindex=6 if incorp=="PA"
		replace nceindex=3 if incorp=="RI"
		replace nceindex=5 if incorp=="SC"
		replace nceindex=4 if incorp=="SC" & pyear>=2011
		replace nceindex=5 if incorp=="SD"
		replace nceindex=7 if incorp=="TN"
		replace nceindex=5 if incorp=="TX"
		replace nceindex=3 if incorp=="TX" & pyear>=1995
		replace nceindex=4 if incorp=="TX" & pyear>=2011
		replace nceindex=6 if incorp=="UT"
		replace nceindex=5 if incorp=="VT"
		replace nceindex=6 if incorp=="VT" & pyear>=2006
		replace nceindex=4 if incorp=="VA" & (1980<=pyear<=1991)
		replace nceindex=3 if incorp=="VA" & (1992<=pyear<=2005)
		replace nceindex=4 if incorp=="VA" & (2006<=pyear<=2013)
		replace nceindex=5 if incorp=="VA" & (2014<=pyear)
		replace nceindex=5 if incorp=="WA"
		replace nceindex=2 if incorp=="WV" 
		replace nceindex=3 if incorp=="WV" & (1984<=pyear<=1991)
		replace nceindex=3 if incorp=="WI"
		replace nceindex=4 if incorp=="WI" & pyear>=2010
		replace nceindex=5 if incorp=="WI" & pyear>=2016
		replace nceindex=4 if incorp=="WY"

		* universal demand law
		gen ud=0
		replace ud=1 if incorp=="UT" & pyear>=1992
		replace ud=1 if incorp=="NH" & pyear>=1993
		replace ud=1 if incorp=="MS" & pyear>=1993
		replace ud=1 if incorp=="NC" & pyear>=1995
		replace ud=1 if incorp=="AZ" & pyear>=1996
		replace ud=1 if incorp=="NE" & pyear>=1996
		replace ud=1 if incorp=="CT" & pyear>=1997
		replace ud=1 if incorp=="ME" & pyear>=1997
		replace ud=1 if incorp=="PA" & pyear>=1997
		replace ud=1 if incorp=="TX" & pyear>=1997
		replace ud=1 if incorp=="WY" & pyear>=1997
		replace ud=1 if incorp=="ID" & pyear>=1998
		replace ud=1 if incorp=="HI" & pyear>=2001
		replace ud=1 if incorp=="IA" & pyear>=2003
		replace ud=1 if incorp=="MA" & pyear>=2004
		replace ud=1 if incorp=="RI" & pyear>=2005
		replace ud=1 if incorp=="SD" & pyear>=2005
		
		* The five most common types of antitakeover laws adopted by states since 1982. The law types are: control share acquisition laws (CS), business combination laws (BC), fair price laws (FP), directors' duties laws (DD), and poison pill laws (PP)
 
		* cs law
		gen cs=0
		replace cs =1 if incorp=="AZ" & pyear>=1987
		replace cs =1 if incorp=="FL" & pyear>=1987
		replace cs =1 if incorp=="HI" & pyear>=1985
		replace cs =1 if incorp=="ID" & pyear>=1988
		replace cs =1 if incorp=="IN" & pyear>=1986
		replace cs =1 if incorp=="KS" & pyear>=1988
		replace cs =1 if incorp=="LA" & pyear>=1987
		replace cs =1 if incorp=="MD" & pyear>=1989
		replace cs =1 if incorp=="MA" & pyear>=1987
		replace cs =1 if incorp=="MI" & pyear>=1988
		replace cs =1 if incorp=="MN" & pyear>=1984
		replace cs =1 if incorp=="MS" & pyear>=1990
		replace cs =1 if incorp=="MO" & pyear>=1984
		replace cs =1 if incorp=="NE" & pyear>=1988
		replace cs =1 if incorp=="NV" & pyear>=1987
		replace cs =1 if incorp=="NC" & pyear>=1987
		replace cs =1 if incorp=="OH" & pyear>=1982
		replace cs =1 if incorp=="OK" & pyear>=1987
		replace cs =1 if incorp=="OR" & pyear>=1987
		replace cs =1 if incorp=="PA" & pyear>=1990
		replace cs =1 if incorp=="SC" & pyear>=1988
		replace cs =1 if incorp=="SD" & pyear>=1990
		replace cs =1 if incorp=="TN" & pyear>=1988
		replace cs =1 if incorp=="UT" & pyear>=1987
		replace cs =1 if incorp=="VA" & pyear>=1989
		replace cs =1 if incorp=="WI" & pyear>=1984
		replace cs =1 if incorp=="WY" & pyear>=1990

		* bc law
		gen bc=0
		replace bc =1 if incorp=="AZ" & pyear>=1987
		replace bc =1 if incorp=="CT" & pyear>=1988
		replace bc =1 if incorp=="DE" & pyear>=1988
		replace bc =1 if incorp=="GA" & pyear>=1988
		replace bc =1 if incorp=="ID" & pyear>=1988
		replace bc =1 if incorp=="IL" & pyear>=1989
		replace bc =1 if incorp=="IN" & pyear>=1986
		replace bc =1 if incorp=="IA" & pyear>=1997
		replace bc =1 if incorp=="KS" & pyear>=1989
		replace bc =1 if incorp=="KY" & pyear>=1986
		replace bc =1 if incorp=="ME" & pyear>=1988
		replace bc =1 if incorp=="MD" & pyear>=1989
		replace bc =1 if incorp=="MA" & pyear>=1989
		replace bc =1 if incorp=="MI" & pyear>=1989
		replace bc =1 if incorp=="MN" & pyear>=1987
		replace bc =1 if incorp=="MO" & pyear>=1986
		replace bc =1 if incorp=="NE" & pyear>=1988
		replace bc =1 if incorp=="NV" & pyear>=1991
		replace bc =1 if incorp=="NJ" & pyear>=1986
		replace bc =1 if incorp=="NY" & pyear>=1985
		replace bc =1 if incorp=="OH" & pyear>=1990
		replace bc =1 if incorp=="OK" & pyear>=1991
		replace bc =1 if incorp=="OR" & pyear>=1991
		replace bc =1 if incorp=="PA" & pyear>=1988
		replace bc =1 if incorp=="RI" & pyear>=1990
		replace bc =1 if incorp=="SC" & pyear>=1988
		replace bc =1 if incorp=="SD" & pyear>=1990
		replace bc =1 if incorp=="TN" & pyear>=1988
		replace bc =1 if incorp=="TX" & pyear>=1997
		replace bc =1 if incorp=="VA" & pyear>=1988
		replace bc =1 if incorp=="WA" & pyear>=1987
		replace bc =1 if incorp=="WI" & pyear>=1987
		replace bc =1 if incorp=="WY" & pyear>=1989

		* fp law
		gen fp=0
		replace fp =1 if incorp=="AZ" & pyear>=1987
		replace fp =1 if incorp=="CT" & pyear>=1984
		replace fp =1 if incorp=="FL" & pyear>=1987
		replace fp =1 if incorp=="GA" & pyear>=1985
		replace fp =1 if incorp=="ID" & pyear>=1988
		replace fp =1 if incorp=="IL" & pyear>=1985
		replace fp =1 if incorp=="IN" & pyear>=1986
		replace fp =1 if incorp=="KY" & pyear>=1984
		replace fp =1 if incorp=="LA" & pyear>=1984
		replace fp =1 if incorp=="MD" & pyear>=1983
		replace fp =1 if incorp=="MI" & pyear>=1984
		replace fp =1 if incorp=="MN" & pyear>=1991
		replace fp =1 if incorp=="MS" & pyear>=1985
		replace fp =1 if incorp=="MO" & pyear>=1986
		replace fp =1 if incorp=="NV" & pyear>=1991
		replace fp =1 if incorp=="NJ" & pyear>=1986
		replace fp =1 if incorp=="NY" & pyear>=1985
		replace fp =1 if incorp=="NC" & pyear>=1987
		replace fp =1 if incorp=="OH" & pyear>=1990
		replace fp =1 if incorp=="PA" & pyear>=1988
		replace fp =1 if incorp=="RI" & pyear>=1990
		replace fp =1 if incorp=="SC" & pyear>=1988
		replace fp =1 if incorp=="SD" & pyear>=1990
		replace fp =1 if incorp=="TN" & pyear>=1988
		replace fp =1 if incorp=="VA" & pyear>=1985
		replace fp =1 if incorp=="WA" & pyear>=1985
		replace fp =1 if incorp=="WI" & pyear>=1984

		* dd law
		gen dd=0
		replace dd =1 if incorp=="AZ" & pyear>=1987
		replace dd =1 if incorp=="CT" & pyear>=1988
		replace dd =1 if incorp=="FL" & pyear>=1989
		replace dd =1 if incorp=="GA" & pyear>=1989
		replace dd =1 if incorp=="HI" & pyear>=1989
		replace dd =1 if incorp=="ID" & pyear>=1988
		replace dd =1 if incorp=="IL" & pyear>=1985
		replace dd =1 if incorp=="IN" & pyear>=1986
		replace dd =1 if incorp=="IA" & pyear>=1989
		replace dd =1 if incorp=="KY" & pyear>=1988
		replace dd =1 if incorp=="LA" & pyear>=1988
		replace dd =1 if incorp=="ME" & pyear>=1985
		replace dd =1 if incorp=="MD" & pyear>=1999
		replace dd =1 if incorp=="MA" & pyear>=1989
		replace dd =1 if incorp=="MN" & pyear>=1987
		replace dd =1 if incorp=="MS" & pyear>=1990
		replace dd =1 if incorp=="MO" & pyear>=1986
		replace dd =1 if incorp=="NE" & pyear>=1988
		replace dd =1 if incorp=="NV" & pyear>=1991
		replace dd =1 if incorp=="NJ" & pyear>=1989
		replace dd =1 if incorp=="NM" & pyear>=1987
		replace dd =1 if incorp=="NY" & pyear>=1987
		replace dd =1 if incorp=="NC" & pyear>=1993
		replace dd =1 if incorp=="ND" & pyear>=1993
		replace dd =1 if incorp=="OH" & pyear>=1984
		replace dd =1 if incorp=="OR" & pyear>=1989
		replace dd =1 if incorp=="PA" & pyear>=1990
		replace dd =1 if incorp=="RI" & pyear>=1990
		replace dd =1 if incorp=="SD" & pyear>=1990
		replace dd =1 if incorp=="TN" & pyear>=1988
		replace dd =1 if incorp=="TX" & pyear>=2003
		replace dd =1 if incorp=="VT" & pyear>=1998
		replace dd =1 if incorp=="VA" & pyear>=1988
		replace dd =1 if incorp=="WI" & pyear>=1987
		replace dd =1 if incorp=="WY" & pyear>=1990

		* pp law
		gen pp=0
		replace pp =1 if incorp=="CO" & pyear>=1989
		replace pp =1 if incorp=="CT" & pyear>=2003
		replace pp =1 if incorp=="FL" & pyear>=1989
		replace pp =1 if incorp=="GA" & pyear>=1988
		replace pp =1 if incorp=="HI" & pyear>=1988
		replace pp =1 if incorp=="ID" & pyear>=1988
		replace pp =1 if incorp=="IL" & pyear>=1989
		replace pp =1 if incorp=="IN" & pyear>=1986
		replace pp =1 if incorp=="IA" & pyear>=1989
		replace pp =1 if incorp=="KY" & pyear>=1988
		replace pp =1 if incorp=="ME" & pyear>=2002
		replace pp =1 if incorp=="MD" & pyear>=1999
		replace pp =1 if incorp=="MA" & pyear>=1989
		replace pp =1 if incorp=="MI" & pyear>=2001
		replace pp =1 if incorp=="MN" & pyear>=1995
		replace pp =1 if incorp=="MS" & pyear>=2005
		replace pp =1 if incorp=="MO" & pyear>=1999
		replace pp =1 if incorp=="NV" & pyear>=1989
		replace pp =1 if incorp=="NJ" & pyear>=1989
		replace pp =1 if incorp=="NY" & pyear>=1988
		replace pp =1 if incorp=="NC" & pyear>=1989
		replace pp =1 if incorp=="OH" & pyear>=1986
		replace pp =1 if incorp=="OR" & pyear>=1989
		replace pp =1 if incorp=="PA" & pyear>=1988
		replace pp =1 if incorp=="RI" & pyear>=1990
		replace pp =1 if incorp=="SC" & pyear>=1998
		replace pp =1 if incorp=="SD" & pyear>=1990
		replace pp =1 if incorp=="TN" & pyear>=1989
		replace pp =1 if incorp=="TX" & pyear>=2003
		replace pp =1 if incorp=="UT" & pyear>=1989
		replace pp =1 if incorp=="VT" & pyear>=2008
		replace pp =1 if incorp=="VA" & pyear>=1990
		replace pp =1 if incorp=="WA" & pyear>=1998
		replace pp =1 if incorp=="WI" & pyear>=1987
		replace pp =1 if incorp=="WY" & pyear>=2009

		* Revlon case
		gen revlon=0
		replace revlon =1 if incorp=="CA" & pyear>=2002
		replace revlon =1 if incorp=="DE" & pyear>=1986
		replace revlon =1 if incorp=="IL" & pyear>=1988
		replace revlon =1 if incorp=="IN" & pyear>=1987
		replace revlon =-1 if incorp=="IN" & pyear>=2001
		replace revlon =1 if incorp=="KS" & pyear>=2003
		replace revlon =-1 if incorp=="MD" & pyear>=2004
		replace revlon =1 if incorp=="MD" & pyear>=2009
		replace revlon =1 if incorp=="MI" & pyear>=1986
		replace revlon =1 if incorp=="MN" & pyear>=1987
		replace revlon =1 if incorp=="MO" & pyear>=1999
		replace revlon =1 if incorp=="NV" & pyear>=1997
		replace revlon =-1 if incorp=="NV" & pyear>=1999
		replace revlon =1 if incorp=="NH" & pyear>=2001
		replace revlon =1 if incorp=="NY" & pyear>=1986
		replace revlon =-1 if incorp=="NY" & pyear>=1997
		replace revlon =-1 if incorp=="NC" & pyear>=2001
		replace revlon =-1 if incorp=="OH" & pyear>=1990
		replace revlon =-1 if incorp=="PA" & pyear>=1987
		replace revlon =-1 if incorp=="VA" & pyear>=1999
		replace revlon =-1 if incorp=="WI" & pyear>=1999
		
		* Unocal case
		gen unocal=0
		replace unocal =1 if incorp=="AR" & pyear>=1993
		replace unocal =1 if incorp=="CA" & pyear>=1989
		replace unocal =1 if incorp=="DE" & pyear>=1985
		replace unocal =1 if incorp=="CA" & pyear>=2002
		replace unocal =1 if incorp=="FL" & pyear>=1989
		replace unocal =1 if incorp=="IL" & pyear>=1988
		replace unocal =1 if incorp=="IN" & pyear>=1987
		replace unocal =-1 if incorp=="IN" & pyear>=2001
		replace unocal =1 if incorp=="KS" & pyear>=2003
		replace unocal =-1 if incorp=="MD" & pyear>=1988
		replace unocal =1 if incorp=="MD" & pyear>=2004
		replace unocal =-1 if incorp=="MA" & pyear>=2003
		replace unocal =1 if incorp=="MI" & pyear>=1986
		replace unocal =1 if incorp=="MN" & pyear>=1987
		replace unocal =1 if incorp=="MO" & pyear>=1999
		replace unocal =-1 if incorp=="NV" & pyear>=1985
		replace unocal =-1 if incorp=="NJ" & pyear>=1998
		replace unocal =-1 if incorp=="NY" & pyear>=1986
		replace unocal =-1 if incorp=="NC" & pyear>=2001
		replace unocal =-1 if incorp=="OH" & pyear>=1986
		replace unocal =-1 if incorp=="PA" & pyear>=1986
		replace unocal =1 if incorp=="TX" & pyear>=1989
		replace unocal =-1 if incorp=="VA" & pyear>=1995
		replace unocal =1 if incorp=="WI" & pyear>=1989

		* Blasius case
		gen blasius=0
		replace blasius =1 if incorp=="CT" & pyear>=2000
		replace blasius =1 if incorp=="DE" & pyear>=1988
		replace blasius =-1 if incorp=="GA" & pyear>=1997
		replace blasius =-1 if incorp=="IN" & pyear>=1993
		replace blasius =-1 if incorp=="IN" & pyear>=2001
		replace blasius =1 if incorp=="KS" & pyear>=2003
		replace blasius =-1 if incorp=="MD" & pyear>=1999
		replace blasius =1 if incorp=="MD" & pyear>=2005
		replace blasius =1 if incorp=="MA" & pyear>=1990
		replace blasius =1 if incorp=="MI" & pyear>=2003
		replace blasius =1 if incorp=="NV" & pyear>=1997
		replace blasius =-1 if incorp=="NV" & pyear>=1999
		replace blasius =-1 if incorp=="NJ" & pyear>=1998
		replace blasius =-1 if incorp=="NC" & pyear>=1984
		replace blasius =-1 if incorp=="OH" & pyear>=1986
		replace blasius =-1 if incorp=="PA" & pyear>=1990
		replace blasius =-1 if incorp=="VA" & pyear>=1986
		
		* Madaroty classified board law
		gen mcb=0
		replace mcb =1 if incorp=="IN" & pyear>=2009
		replace mcb =1 if incorp=="IA" & pyear>=2011
		replace mcb =-1 if incorp=="IA" & pyear>=2014
		replace mcb =1 if incorp=="MA" & pyear>=1990
		replace mcb =1 if incorp=="OK" & pyear>=2010
		replace mcb =-1 if incorp=="OK" & pyear>=2013

		
************************************	
* Table 10 HQ state = Incorp state *
************************************	

		reghdfe ln_patcountpyear_adj cow if incorp==state, absorb(inventor_id pyear#patgroupFE) vce(robust )
		reghdfe ln_patcitespyear_countclassadjt cow  if istate==lstate, absorb(inventor_id  pyear#patclassFE) vce(robust)
		reghdfe ln_patcitespyear_fyearadj cow  if istate==lstate, absorb(inventor_id  pyear#patclassFE) vce(robust)
		reghdfe generality cow if istate==lstate , absorb(inventor_id  pyear#patgroupFE) vce(robust)
		reghdfe originality cow if istate==lstate , absorb(inventor_id  pyear#patgroupFE) vce(robust)
		
				
**************************	
* Table 11 Drop DE firms *
**************************	

		reghdfe ln_patcountpyear_adj cow if state~="DE", absorb(inventor_id pyear#patgroupFE) vce(robust )
		reghdfe ln_patcitespyear_countclassadjt cow if state~="DE" , absorb(inventor_id pyear#patclassFE) vce(robust)
		reghdfe generality cow if state~="DE" , absorb(inventor_id pyear#patgroupFE) vce(robust)
		reghdfe originality cow if state~="DE" , absorb(inventor_id pyear#patgroupFE) vce(robust)

		
**************************************	
* Table 13 Additional legal controls *
**************************************

		reghdfe ln_patcountpyear_adj cow nceindex ud mcb cs bc fp dd pp revlon unocal blasius , absorb(inventor_id pyear#patgroupFE) vce(robust)
		reghdfe ln_patcitespyear_countclassadjt cow nceindex ud mcb cs bc fp dd pp revlon unocal blasius, absorb(inventor_id permno pyear#patclassFE) vce(robust)
		reghdfe generality cow nceindex ud mcb cs bc fp dd pp revlon unocal blasius, absorb(inventor_id permno pyear#patgroupFE) vce(robust)
		reghdfe originality cow nceindex ud mcb cs bc fp dd pp revlon unocal blasius, absorb(inventor_id permno pyear#patgroupFE) vce(robust)

				
*******************************************	
* Table 14 High dimensional fixed effects *
*******************************************	

		reghdfe ln_patcountpyear_adj cow, absorb(inventor_id lstateFE#pyear#patgroupFE) vce(cluster permno)
		reghdfe ln_patcitespyear_countclassadjt cow , absorb(inventor_id  lstateFE#pyear#patclassFE) vce(cluster permno)
		reghdfe generality cow , absorb(inventor_id  lstateFE#pyear#patgroupFE) vce(cluster permno)
		reghdfe originality cow , absorb(inventor_id  lstateFE#pyear#patgroupFE) vce(cluster permno)
		
				
************************	
* Table 15 Matched DiD *
************************
		
		psmatch2 treatment i.lstateFE i.pyear i.patgroupFE, n(1)		
		bys permno: egen matching_sample = sum(_weight)
		reghdfe ln_patcountpyear_adj cow if matching_sample!=0, absorb(inventor_id pyear#patgroupFE) vce(robust )
		reghdfe ln_patcitespyear_countclassadj cow if matching_sample!=0, absorb(inventor_id pyear#patclassFE) vce(robust)
		reghdfe generality cow if matching_sample!=0, absorb(inventor_id pyear#patgroupFE) vce(robust)
		reghdfe originality cow if matching_sample!=0, absorb(permno pyear#patgroupFE) vce(robust)

				
************************		
* Table 16 Stacked DiD *
************************		

		expand 2, gen(event_DE)
		drop if event_DE==1 & treatment==1 & incorp~="DE" 
		drop if event_DE==1 & (pyear<1996 | pyear>2004)

		expand 2 if event_DE==0, gen(event_OK)
		drop if event_OK==1 & treatment==1 & incorp~="OK"
		drop if event_OK==1 & (pyear<1997 | pyear>2005)

		expand 2 if event_DE==0 & event_OK==0, gen(event_MO)
		drop if event_MO==1 & treatment==1 & incorp~="MO"
		drop if event_MO==1 & (pyear<1999 | pyear>2007)
		
		expand 2 if event_DE==0 & event_OK==0 & event_MO==0, gen(event_KS)
		drop if event_KS==1 & treatment==1 & incorp~="KS"
		drop if event_KS==1 & (pyear<2001 | pyear>2009)
		
		expand 2 if event_DE==0 & event_OK==0 & event_MO==0 & event_KS==0, gen(event_TX)
		drop if event_TX==1 & treatment==1 & incorp~="TX"
		drop if event_TX==1 & (pyear<2002 | pyear>2010)
		
		expand 2 if event_DE==0 & event_OK==0 & event_MO==0 & event_KS==0 & event_TX==0, gen(event_NV)
		drop if event_NV==1 & treatment==1 & incorp~="NV"
		drop if event_NV==1 & (pyear<2003 | pyear>2011)
		
		expand 2 if event_DE==0 & event_OK==0 & event_MO==0 & event_KS==0 & event_TX==0 & event_NV==0, gen(event_NJ)
		drop if event_NJ==1 & treatment==1 & incorp~="NJ"
		drop if event_NJ==1 & (pyear<2007 | pyear>2015)
		
		expand 2 if event_DE==0 & event_OK==0 & event_MO==0 & event_KS==0 & event_TX==0 & event_NV==0 & event_NJ==0, gen(event_MD)
		drop if event_MD==1 & treatment==1 & incorp~="MD"
		drop if event_MD==1 & (pyear<2010 | pyear>2018) 
		
		expand 2 if event_DE==0 & event_OK==0 & event_MO==0 & event_KS==0 & event_TX==0 & event_NV==0 & event_NJ==0 & event_MD==0, gen(event_WA)
		drop if event_WA==1 & treatment==1 & incorp~="WA"
		drop if event_WA==1 & (pyear<2012 | pyear>2020)
		
		drop if event_DE==0 & event_OK==0 & event_MO==0 & event_KS==0 & event_TX==0 & event_NV==0 & event_NJ==0 & event_MD==0 & event_WA==0
	
		reghdfe ln_patcountpyear_adj cow , absorb(inventor_id pyear#patgroupFE) vce(robust )
		reghdfe ln_patcitespyear_countclassadjt cow , absorb(inventor_id pyear#patclassFE) vce(robust)
		reghdfe generality cow , absorb(inventor_id pyear#patgroupFE) vce(robust)
		reghdfe originality cow , absorb(inventor_id pyear#patgroupFE) vce(robust)
	

********************************
* Table B3 Dynamic coeff trend *
********************************

	clear all
	global path "C:\cow"
	global out "$path\out"
	use "$path\inventor_stayer.dta"
	set more off

	*Convert strings to numerics
	encode state, gen(lstateFE)
	encode incorp, gen(istateFE)
	encode patgroup, gen(patgroupFE)
	encode class, gen(patclassFE)

	*Set timeframe 
	drop if pyear < 1996 
	drop if pyear > 2018 
		

	*Drop if missing headquarter state
	drop if missing(state)
	*Drop if missing state of incorporation
	drop if missing(incorp)
	*Drop if not incorporated in U.S. state
	drop if inlist(incorp, "AS", "INTL", "PR", "TT", "VI")

	
	drop if missing(permno)

	keep if leaving==0

	*Generate variables
	
	gen patcitespyear_countclassadjt=patcitespyear_countclassadj*1000
	gen patcites5pyear_countclassadjt=patcites5pyear_countclassadj*1000
	
	local pat "patcountpyear patcountpyear_adj patcountpyear_fclassadj patcitespyear patcitespyear_countclassadj patcitespyear_countclassadjt patcitespyear_fyearadj  patcitespyear_fclassadj  patcitespyear_fyearadjt  patcitespyear_fclassadjt  generality originality originality_alt patcites5pyear patcites5pyear_countclassadj patcites5pyear_countclassadjt patcites5pyear_fyearadj  patcites5pyear_fclassadj  patcites5pyear_fyearadjt  patcites5pyear_fclassadjt  generality5 originality5  " 
	foreach v of local pat {
		replace `v'=0 if missing(`v')
		gen ln_`v' = log(1+`v')
	}
	

	local statelist "DE OK MO KS TX NV NJ MD WA"
	gen treatment = 0
	foreach state of local statelist {
			replace treatment = 1 if incorp == "`state'"
	}

	*Create macros for year in which law was passed
	local DE_cow = 2001
	local OK_cow = 2002
	local MO_cow = 2004
	local KS_cow = 2005
	local TX_cow = 2006
	local NV_cow = 2008
	local NJ_cow = 2011
	local MD_cow = 2015
	local WA_cow = 2016

	*Initiate statelist macro
	local statelist "DE OK MO KS TX NV NJ MD WA"

	*cow: indicator equal to one if firm is incorporated in a state that has passed a corporate opportunities law
	gen cow = 0
	foreach state of local statelist {
			replace cow = 1 if incorp == "`state'" & pyear >= ``state'_cow'
	}

		
		*Initialize variables
		forval x=1/25 {
			gen cown`x'=0
			}

		forval x=0/25 {
			gen cow`x'=0
			}


		gen cow2p = 0
		gen cow3p = 0
		gen cow4p = 0

		*Generate event time index
		gen indexyear=0
		foreach state of local statelist {
			forval x=-25(1)25 {
			replace indexyear=`x' if incorp == "`state'" & pyear == ``state'_cow'+`x'
			}
			}	
		
		*Generate event time dummies
		foreach state of local statelist {
			forval x=1/25 {
			replace cown`x' = 1 if incorp == "`state'" & pyear == ``state'_cow'-`x'
			}
			}	
			
		foreach state of local statelist {
			forval x=0/25 {
			replace cow`x' = 1 if incorp == "`state'" & pyear == ``state'_cow'+`x'
			}
			}
			
		foreach state of local statelist {
			replace cow2p = 1 if incorp == "`state'" & pyear >= ``state'_cow'+2
			replace cow3p = 1 if incorp == "`state'" & pyear >= ``state'_cow'+3
			replace cow4p = 1 if incorp == "`state'" & pyear >= ``state'_cow'+4
			}

	* dynamic coeff
		reghdfe ln_patcountpyear_adj cown2 cown1 cow0 cow1 cow2 cow3p , absorb(inventor_id pyear#patgroupFE) vce(robust )
		reghdfe ln_patcitespyear_countclassadjt cown2 cown1 cow0 cow1 cow2 cow3p , absorb(inventor_id permno pyear#patclassFE) vce(robust)
		reghdfe generality cown2 cown1 cow0 cow1 cow2 cow3p , absorb(inventor_id permno pyear#patgroupFE) vce(robust)
		reghdfe originality cown2 cown1 cow0 cow1 cow2 cow3p , absorb(inventor_id permno pyear#patgroupFE) vce(robust)
		


*******************************
* Figure B2 Block permutation *
*******************************	
		
	clear all
	global path "C:\cow"
	global out "$path\out"
	use "$path\inventor_stayer.dta"
	set more off

	encode state, gen(lstateFE)
	encode patgroup, gen(patgroupFE)
	encode class, gen(patclassFE)

	drop if pyear < 1996 
	drop if pyear > 2018 
		
	drop if missing(state)
	drop if missing(incorp)
	drop if inlist(incorp, "AS", "INTL", "PR", "TT", "VI")
	drop if missing(permno)
	keep if leaving==0

	local pat " patcountpyear_adj patcitespyear_countclassadjt" 
	foreach v of local pat {
		replace `v'=0 if missing(`v')
		gen ln_`v' = log(1+`v')
	}
	
	* Loop 1000;
		forval y= 1/1000 {
		bysort permno: gen ryear_`y' = runiformint(1996,2018)
		bysort permno: replace ryear_`y' = ryear_`y'[1]
		bysort permno: gen treatment_`y' = runiformint(0,1)
		bysort permno: replace treatment_`y' = treatment_`y'[1]
		gen cow_`y' =0
		replace cow_`y' =1 if treatment_`y'==1 & pyear >= ryear_`y'
	
		quietly reghdfe ln_patcountpyear_adj cow_`y' , absorb(inventor_id pyear#patgroupFE) vce(robust )
		estimate store m`y'
		drop ryear_`y' treatment_`y' cow_`y'   
		}

		estout m* using "patcount_loop1.csv", cells(b) replace
		
		
	clear all
	global path "C:\cow"
	global out "$path\out"
	use "$path\inventor_stayer.dta"
	set more off

	encode state, gen(lstateFE)
	encode patgroup, gen(patgroupFE)
	encode class, gen(patclassFE)

	drop if pyear < 1996 
	drop if pyear > 2018 
		
	drop if missing(state)
	drop if missing(incorp)
	drop if inlist(incorp, "AS", "INTL", "PR", "TT", "VI")
	drop if missing(permno)
	keep if leaving==0

	local pat " patcountpyear_adj patcitespyear_countclassadjt" 
	foreach v of local pat {
		replace `v'=0 if missing(`v')
		gen ln_`v' = log(1+`v')
	}
	
	* Loop 1000;
		forval y= 1/1000 {
		bysort permno: gen ryear_`y' = runiformint(1996,2018)
		bysort permno: replace ryear_`y' = ryear_`y'[1]
		bysort permno: gen treatment_`y' = runiformint(0,1)
		bysort permno: replace treatment_`y' = treatment_`y'[1]
		gen cow_`y' =0
		replace cow_`y' =1 if treatment_`y'==1 & pyear >= ryear_`y'
	
		quietly reghdfe ln_patcitespyear_countclassadjt cow_`y' , absorb(inventor_id permno pyear#patclassFE) vce(robust)
		estimate store m`y'
		drop ryear_`y' treatment_`y' cow_`y'   
		}

		estout m* using "patcites_loop1.csv", cells(b) replace

		
	clear all
	global path "C:\cow"
	global out "$path\out"
	use "$path\inventor_stayer.dta"
	set more off

	encode state, gen(lstateFE)
	encode patgroup, gen(patgroupFE)
	encode class, gen(patclassFE)

	drop if pyear < 1996 
	drop if pyear > 2018 
		
	drop if missing(state)
	drop if missing(incorp)
	drop if inlist(incorp, "AS", "INTL", "PR", "TT", "VI")
	drop if missing(permno)
	keep if leaving==0

	
	* Loop 1000;
		forval y= 1/1000 {
		bysort permno: gen ryear_`y' = runiformint(1996,2018)
		bysort permno: replace ryear_`y' = ryear_`y'[1]
		bysort permno: gen treatment_`y' = runiformint(0,1)
		bysort permno: replace treatment_`y' = treatment_`y'[1]
		gen cow_`y' =0
		replace cow_`y' =1 if treatment_`y'==1 & pyear >= ryear_`y'
	
		quietly reghdfe generality cow_`y' , absorb(inventor_id permno pyear#patgroupFE) vce(robust)
		estimate store m`y'
		drop ryear_`y' treatment_`y' cow_`y'   
		}

		estout m* using "generality_loop1.csv", cells(b) replace		


	clear all
	global path "C:\cow"
	global out "$path\out"
	use "$path\inventor_stayer.dta"
	set more off

	encode state, gen(lstateFE)
	encode patgroup, gen(patgroupFE)
	encode class, gen(patclassFE)

	drop if pyear < 1996 
	drop if pyear > 2018 
		
	drop if missing(state)
	drop if missing(incorp)
	drop if inlist(incorp, "AS", "INTL", "PR", "TT", "VI")
	drop if missing(permno)
	keep if leaving==0

	
	* Loop 1000;
		forval y= 1/1000 {
		bysort permno: gen ryear_`y' = runiformint(1996,2018)
		bysort permno: replace ryear_`y' = ryear_`y'[1]
		bysort permno: gen treatment_`y' = runiformint(0,1)
		bysort permno: replace treatment_`y' = treatment_`y'[1]
		gen cow_`y' =0
		replace cow_`y' =1 if treatment_`y'==1 & pyear >= ryear_`y'
	
		quietly reghdfe originality cow_`y' , absorb(inventor_id permno pyear#patgroupFE) vce(robust)
		estimate store m`y'
		drop ryear_`y' treatment_`y' cow_`y'   
		}

		estout m* using "originality_loop1.csv", cells(b) replace		

		
